<!DOCTYPE HTML>
<html>
<head>
<!--#header start-->
{include file="public/_meta" /}
<!--#header end-->
<title>栏目管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
	<span class="c-gray en">&gt;</span>
	系统管理
	<span class="c-gray en">&gt;</span>
	菜单管理
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="page-container">
	<!--<div class="text-c">
		<input type="text" name="" id="" placeholder="栏目名称、id" style="width:250px" class="input-text">
		<button name="" id="" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
	</div>-->
	<div class="cl pd-5 bg-1 bk-gray mt-20">
		<span class="l">
		<a href="javascript:;" onclick="javascript:datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
		<a class="btn btn-primary radius" onclick="add('添加菜单节点','{:url('auth/create')}')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加菜单/节点</a>
		</span>
	</div>
	<div class="mt-20">
		<table class="table table-border table-bordered table-hover table-bg table-sort">
			<thead>
				<tr class="text-c">
					<th width="25"><input type="checkbox" name="" value=""></th>
					<th width="80">ID</th>
					<th width="80" class="hidden-xs visible-md-*">排序</th>
					<th width="150">节点</th>
					<th width="200">节点名称</th>
					<th width="350" class="hidden-xs visible-md-*">节点描述</th>
					<th width="60" class="hidden-xs visible-md-*">节点图标</th>
					<th class="hidden-xs visible-md-*" width="150">校验规则</th>
					<th width="60" class="hidden-xs visible-md-*">显示/隐藏</th>
					<th width="60" class="hidden-xs visible-md-*">启用/禁用</th>
					<th width="200">操作</th>

				</tr>
			</thead>
			<tbody>
 				{volist name="ruleList" id="list"}
 							<tr class="text-c">
 								<td ><input  name="id[]" type="checkbox" value="{$list.id}"></td>
 								<td style="color:#08c;">{$list.id}</td>
 								<td class="hidden-xs visible-md-*"><input type="text" class="input-text radius size-M"  value="{$list.sort}" onblur="update_sort(this.value,{$list.id});"></td>
 								<td class="text-l" style="color:#08c;">{$list.name}</td>
 								<td class="text-l " style="color:#08c;">{$list.menu_name}</td>
 								<td class="text-l hidden-xs visible-md-*" style="color:#08c;">{$list.title}</td>
 								<td class="hidden-xs visible-md-*" style="color:#08c;"><i class="Hui-iconfont" >{$list.icon}</i></td>
 								<td class="hidden-xs visible-md-*" style="color:#08c;">{$list.condition}</td>
								<td class="hidden-xs visible-md-*">
									{if condition="$list.is_show"}
									 <a href="javascript:;" onclick="update_is_show('隐藏',0,{$list.id});" ><span class="label label-success radius ">显示</span></a>
									{else /}
									 <a href="javascript:;" onclick="update_is_show('显示',1,{$list.id});" ><span class="label label-default radius ">隐藏</span></a>
									{/if}
								</td>
								<td class="hidden-xs visible-md-*">
										{if condition="$list.status"}
										<a href="javascript:;" onclick="update_status('禁用',0,{$list.id});" ><span class="label label-secondary radius ">启用</span></a>
										{else /}
										<a href="javascript:;" onclick="update_status('启用',1,{$list.id});" ><span class="label label-danger radius ">禁用</span></a>
										{/if}
								</td>
 								<td class="f-14" >
									<a class="btn btn-warning radius size-MINI" title="编辑" href="javascript:;" onclick="edit('节点编辑','{:url('Auth/edit')}?id={$list.id}','1','800','720')" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
									{if condition="$list.can_delete"}
									   <a class="btn btn-danger radius size-MINI" title="删除" href="javascript:;" onclick="del(this,'{$list.id}')" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
								  {else /}
									   <a class="btn btn-danger-outline radius size-MINI" href="javascript:;"  data-toggle="tooltip" data-placement="top" title="此菜单不能删除">
										    <i class="Hui-iconfont">&#xe6e2;</i>
									   </a>
								 {/if}
								</td>
 							</tr>
 							{if condition="array_key_exists('child',$list)"}
 									{volist name="list.child" id="sonList"}
 										<!-- 子循环 -->
 										<tr class="text-c">
 											<td><input name="id[]" type="checkbox" value="{$sonList.id}"></td>
										<td>{$sonList.id}</td>
										<td class="hidden-xs visible-md-*"><input type="text" class="input-text radius size-M"  value="{$sonList.sort}" onblur="update_sort(this.value,{$sonList.id});"></td>
										<td class="text-l">{$sonList.name}</td>
			 								<td class="text-l">&nbsp;&nbsp;├&nbsp;{$sonList.menu_name}</td>
			 								<td class="hidden-xs visible-md-*">{$sonList.title}</td>
			 								<td class="hidden-xs visible-md-*"><i class="Hui-iconfont">{$sonList.icon}</i></td>
			 								<td class="hidden-xs visible-md-*">{$sonList.condition}</td>
			 								<td class="hidden-xs visible-md-*">
												{if condition="$sonList.is_show"}
											  	<a href="javascript:;" onclick="update_is_show('隐藏',0,{$sonList.id});" ><span class="label label-success-outline radius">显示</span></a>
											  {else /}
												  <a href="javascript:;" onclick="update_is_show('显示',1,{$sonList.id});" ><span class="label label-default-outline radius">隐藏</span></a>
												{/if}
											</td>
			 								<td class="hidden-xs visible-md-*">
													{if condition="$sonList.status"}
													<a href="javascript:;" onclick="update_status('禁用',0,{$sonList.id});"><span class="label label-secondary radius">启用</span></a>
													{else /}
													<a href="javascript:;" onclick="update_status('启用',1,{$sonList.id});" ><span class="label label-danger radius">禁用</span></a>
                          {/if}
											</td>
 											<td class="f-14">
												<a class="btn btn-primary radius size-MINI" title="编辑" href="javascript:;" onclick="edit('节点编辑','{:url('Auth/edit')}?id={$sonList.id}','2','800','740')" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>

												 	{if condition="$sonList.can_delete"}
													<a class="btn btn-danger radius size-MINI" title="删除" href="javascript:;" onclick="del(this,'{$sonList.id}')" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
													{else /}
														<a class="btn btn-danger-outline radius size-MINI" href="javascript:;"  data-toggle="tooltip" data-placement="top" title="此菜单不能删除">
															<i class="Hui-iconfont">&#xe6e2;</i>
														</a>
													{/if}
 										</tr>
 										<!-- 子循环 end-->
 									 {/volist}
 							{/if}
 				{/volist}
			</tbody>
		</table>
	</div>
</div>
<!--#header start-->
{include file="public/_footer" /}
<!--#header end-->

<!--请在下方写此页面业务相关的脚本-->
<!--<script type="text/javascript" src="__ADMIN__/lib/My97DatePicker/4.8/WdatePicker.js"></script>-->
<script type="text/javascript" src="__ADMIN__/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="__ADMIN__/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
$('.table-sort').dataTable({
	 'ordering':  true ,
     "iDisplayLength": 50
});

/*系统-栏目-添加*/
function add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*系统-栏目-编辑*/
function edit(title,url,id,w,h){
	layer_show(title,url,w,h);
}
/*系统-栏目-删除*/
function del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'DELETE',
			url: "{:url('Auth/delete')}",
			data:{id:id},
			dataType: 'json',
			success: function(result){
				console.log(result);
				$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
			},
			error:function(data) {
				//console.log(data.msg);
			},
		});
	});
}

/*系统-栏目-更新排序*/
function update_sort(sort,id){
	$.ajax({
		type: 'PUT',
		url: "{:url('Auth/update')}",
		data: {sort:sort,id:id},
		dataType: 'json',
		success: function(result){
			if (result.state) {
				layer.msg(result.msg,{icon:1,time:1000});
			}else {
				layer.msg(result.msg,{icon:5,time:1000});
			}
		}
	});
}

/*系统-栏目-更新状态*/
function update_status(msg,status,id){
	layer.msg('确认更新启用状态', {
     time: 2000, //20s后自动关闭
     btn: [ msg , '放弃']
   },function(){
		 layer.load(0, {
       shade: [0.1,'#fff'] //0.1透明度的白色背景
     });

		 $.ajax({
			 type: 'PUT',
			 url: "{:url('Auth/update')}",
			 data: {status:status,id:id},
			 dataType: 'json',
			 success: function(result){
				 if (result.state) {
					 layer.msg(result.msg,{icon:1,time:1000});
					  // location.replace(location.href);
				 }else {
					 layer.msg(result.msg,{icon:5,time:1000});
				 }
			 }
		 });

		setTimeout(function(){
			layer.closeAll('loading');
	  }, 3000);

	}, function(){
    layer.closeAll('loading');
	});
}

/*系统-栏目-更新显示*/
function update_is_show(msg,is_show,id){
	layer.confirm('确认更新显示状态', {
     time: 5000, //5s后自动关闭
     btn: [ msg , '放弃']
   },function(){
		 layer.load(0, {
       shade: [0.1,'#fff'] //0.1透明度的白色背景
     });

		 $.ajax({
			 type: 'PUT',
			 url: "{:url('Auth/update')}",
			 data: {is_show:is_show,id:id},
			 dataType: 'json',
			 success: function(result){
				 if (result.state) {
					 layer.msg(result.msg,{icon:1,time:1000});
					//  location.replace(location.href);
				 }else {
					 layer.msg(result.msg,{icon:5,time:1000});
				 }
			 }
		 });

		 setTimeout(function(){
 			layer.closeAll('loading');
 	  }, 3000);

	}, function(){
    layer.closeAll('loading');
	});
}

/*管理员-批量删除*/
function datadel(){
	var chk_value =[];
  $('input[name="id[]"]:checked').each(function(){
    chk_value.push($(this).val());
  });
  if (chk_value.length==0 ) {
 	  layer.msg('未选中任意项', {icon: 5,time:1000});
	}else {
		$.ajax({
			type: 'DELETE',
			url: "{:url('Auth/delete')}",
			data:{id:chk_value},
			dataType: 'json',
			success: function(data){
					if(data.state){
						$(obj).parents("tr").remove();
						layer.msg(data.msg,{icon:1,time:1000});
					}else {
						layer.msg(data.msg,{icon:5,time:1000});
					}
			}
		});
	}

}

</script>

</body>
</html>
